// admin/system/service/sys_user_post_service.go
package service

import (
	repo "go-admin1/admin/system/dao"
	"go-admin1/admin/system/model"
)

// SysUserPostService 用户岗位关联服务接口
type SysUserPostService interface {
	Create(userPost *model.SysUserPost) error
	GetByUserID(userID int64) ([]*model.SysUserPost, error)
	GetByPostID(postID int64) ([]*model.SysUserPost, error)
	DeleteByUserID(userID int64) error
	DeleteByPostID(postID int64) error
	DeleteByUserIDAndPostID(userID, postID int64) error
	ListPostIDsByUserID(userID int64) ([]int64, error)
	ListUserIDsByPostID(postID int64) ([]int64, error)
}

type sysUserPostService struct {
	userPostDao repo.SysUserPostDao
}

func (s sysUserPostService) Create(userPost *model.SysUserPost) error {
	return s.userPostDao.Create(userPost)
}

func (s sysUserPostService) GetByUserID(userID int64) ([]*model.SysUserPost, error) {
	userPosts, err := s.userPostDao.GetByUserID(userID)
	if err != nil {
		return nil, err
	}
	return userPosts, nil
}

func (s sysUserPostService) GetByPostID(postID int64) ([]*model.SysUserPost, error) {
	userPosts, err := s.userPostDao.GetByPostID(postID)
	if err != nil {
		return nil, err
	}
	return userPosts, nil
}

func (s sysUserPostService) DeleteByUserID(userID int64) error {
	return s.userPostDao.DeleteByUserID(userID)
}

func (s sysUserPostService) DeleteByPostID(postID int64) error {
	return s.userPostDao.DeleteByPostID(postID)
}

func (s sysUserPostService) DeleteByUserIDAndPostID(userID, postID int64) error {
	return s.userPostDao.DeleteByUserIDAndPostID(userID, postID)
}

func (s sysUserPostService) ListPostIDsByUserID(userID int64) ([]int64, error) {
	postIDs, err := s.userPostDao.ListPostIDsByUserID(userID)
	if err != nil {
		return nil, err
	}
	return postIDs, nil
}

func (s sysUserPostService) ListUserIDsByPostID(postID int64) ([]int64, error) {
	userIDs, err := s.userPostDao.ListUserIDsByPostID(postID)
	if err != nil {
		return nil, err
	}
	return userIDs, nil
}

// NewSysUserPostService 创建用户岗位关联服务实例
func NewSysUserPostService() SysUserPostService {
	return &sysUserPostService{
		userPostDao: repo.NewSysUserPostDao(),
	}
}
